package com.stone.framework.batch.job;

import javax.sql.DataSource;

import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepScope;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.stone.framework.batch.tasklet.JdbcTemplateTasklet;

@Configuration
public class BatchStateStage1SettingJob {

    @Autowired
    private JobBuilderFactory jobBuilderFactory;

    @Autowired
    private StepBuilderFactory stepBuilderFactory;

    @Autowired
    @Qualifier("dataSourceSecond")
    private DataSource dataSource;

    @Bean("job_batchStateStage1Setting")
    public Job job() {
        return jobBuilderFactory.get("job_batchStateStage1Setting").start(step1()).build();
    }

    @Bean("step_batchStateStage1Setting_DBUpdating")
    public Step step1() {
        return stepBuilderFactory.get("step_batchStateStage1Setting_DBUpdating").tasklet(tasklet1()).build();
    }

    @StepScope
    @Bean("tasklet_batchStateStage1Setting_DBUpdating")
    public Tasklet tasklet1() {
        JdbcTemplateTasklet tasklet = new JdbcTemplateTasklet();
        tasklet.setDataSource(dataSource);
        tasklet.setSqls(
            "update udf_config uu set uu.value_ = 'safe', uu.update_date = sysdate where uu.key_ = 'sysModel'",
            "update udf_config uu set uu.value_ = '0', uu.update_date = sysdate where uu.key_ = 'xyfqBatchState'",
            "update udf_config uu set uu.value_ = '0', uu.update_date = sysdate where uu.key_ = 'xfjmBatchState'",
            // TODO update armc_ci_cust t set t.today_call = 0 是否可删除
            "update armc_ci_cust t set t.today_call = 0 where t.today_call = 1 and t.bank_code = '0305' and t.inst_code = '0305'");
        return tasklet;
    }

}
